﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Search : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ViewState["Tesss"] = "Testt";
    }
 
    protected void Page_Error(object sender, EventArgs e)
    {

    }
    protected void CheckBox3_CheckedChanged(object sender, EventArgs e)
    {
        loaiPhongDropList.Visible = loaiPhongCheck.Checked;
        
    }
    protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
    {
        veRadioList.Visible = datVeCheck.Checked;
        //System.Diagnostics.Trace.WriteLineIf(true, "tes");
        Session["Testtt"] = "test";
        Server.Transfer("~/Navigate.aspx", true);

        //Trace.Warn("CheckBox", "veRadioList.Visible =" + int.Parse(veRadioList.Visible.ToString()));
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        NameValueCollection queryString = new NameValueCollection();

        // Khu vực
        messageText.Text = "Tên khu vực : " + khuVucText.Text + Environment.NewLine;
        queryString.Add("tkv", khuVucText.Text);

        // Số sao
        messageText.Text += "Số sao : ";
        //for (int i = 0; i < CheckBoxList1.Items.Count - 2; i++)
        //    item = CheckBoxList1.Items[i];

        foreach (ListItem item in starCheckList.Items)
            if (item.Selected)
            {
                messageText.Text += item.Text + ", ";
                queryString.Add("star", item.Value);
            }

        messageText.Text += "\r\nDịch vụ khác : ";
        messageText.Text += nhaHangCheck.Checked ? nhaHangCheck.Text : "";
        messageText.Text += thangMayCheck.Checked ? thangMayCheck.Text : "";

        queryString.Add("nh", nhaHangCheck.Checked ? nhaHangCheck.Text : "");
        queryString.Add("tm", thangMayCheck.Checked ? thangMayCheck.Text : "");

        if (loaiPhongCheck.Checked)
        {
            messageText.Text += "\r\nLoại phòng : " + loaiPhongDropList.SelectedItem.Text;
            queryString.Add("lp", loaiPhongDropList.SelectedValue);
        }

        if (datVeCheck.Checked)
        {
            messageText.Text += "\r\nĐặt vé : " + veRadioList.SelectedItem.Text;
            queryString.Add("dv", veRadioList.SelectedValue);
        }

        // Từ NameValueCollection -> string dạng name1=value1&name2=value2
        string query = "";
        foreach (string key in queryString.Keys)
        {
            query += Server.UrlEncode(key) + "=" + Server.UrlEncode(queryString.Get(key)) + "&";
            // UrlEncode -> Encode -> mã hóa
        }

        messageText.Text += "\r\n" + query;
        messageText.Text += "\r\n" + Request.MapPath("~/Test/CopyResult.aspx");
        Response.Write(Server.UrlEncode("<script>alert('Hello')</script>"));
        Server.Execute("~/Login.aspx");
    }
}